package Java.BlackHorse.doudizu3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;

public class PokerGame {
    static HashMap<String,Integer> hm = new HashMap<>();
    static ArrayList<String> list = new ArrayList<>();

    static{
        //准备牌
        String[] color = {"♣", "♦", "♥", "♠"};
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        for (String c : color) {
            for (String n : number) {
                list.add(c+n);
            }
        }
        list.add(" 小王");
        list.add(" 大王");

        //指定牌的价值
        hm.put("J",11);
        hm.put("Q",12);
        hm.put("K",13);
        hm.put("A",14);
        hm.put("2",15);
        hm.put("小王",50);
        hm.put("大王",100);

    }

    PokerGame(){
        //洗牌
        Collections.shuffle(list);

        //发牌
        ArrayList<String> lord = new ArrayList<>();
        ArrayList<String> Player1 = new ArrayList<>();
        ArrayList<String> Player2 = new ArrayList<>();
        ArrayList<String> Player3 = new ArrayList<>();

        for(int i = 0; i < list.size();i++){
            String a = list.get(i);

            if(i<=2){
                lord.add(a);
            }
            if(i % 3 == 0){
                Player1.add(a);
            }else{
                if(i % 3 == 1){
                    Player2.add(a);
                }else{
                    Player3.add(a);
                }
            }
        }

        //排序
        order(lord);
        order(Player1);
        order(Player2);
        order(Player3);

        //发牌
        lookPoker("麻子",Player1);
        lookPoker("二狗",Player2);
        lookPoker("富贵",Player3);
        lookPoker("底牌",lord);

    }
    public void order(ArrayList<String> list){
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                String color1 =o1.substring(0,1);
                String color2 =o2.substring(0,1);
                int number1 = getValue(o1);
                int number2 = getValue(o2);

                int i=number1-number2;

                return i==0 ? color1.compareTo(color2) : i;
            }
        });
    }

    public int getValue(String poker){
        String number = poker.substring(1);
        if(hm.containsKey(number)){
            return hm.get(number);
        }else{
            return Integer.parseInt(number);
        }
    }

    public void lookPoker(String name,ArrayList<String> list){
        System.out.print(name+":");
        for(String p : list){
            System.out.print(p+" ");
        }
        System.out.println();
    }
}
